using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;

namespace caseDrawer
{
	public partial class ResultForm : Form
	{

		DataTable pdt = new DataTable();
		DataTable ndt = new DataTable();

		int parentFormX,parentFormY;
		public int ParentFormX{
			set{parentFormX = value;}
		}
		public int ParentFormY{
			set{parentFormY = value;}
		}

		string brickId;
		public string BrickId{
			set{ brickId = value; }
		}

		public ResultForm(string brickId)
		{
			this.brickId = brickId;

			InitializeComponent();

			setPosition();

			loadPositiveResults();
			loadNegativeResults();
			fillResultGridView();
		}

		void setPosition(){


		}

		void loadPositiveResults(){
			pdt = Database.Instance.loadResults(this.brickId,'P');

		}

		void loadNegativeResults(){
			ndt = Database.Instance.loadResults(this.brickId,'N');
		}

		void fillResultGridView(){
			positiveGridView.DataSource = pdt;

			negativeGridView.DataSource = ndt;
		}


		void BtSaveClick(object sender, EventArgs e)
		{
			foreach(DataGridViewRow row in positiveGridView.Rows){
				if(row.IsNewRow)
					break;

				Result result = new Result(brickId);
				if(row.Cells[0].Value.ToString()!=null)
					result.Id		= row.Cells[0].Value.ToString();

				result.Input		= row.Cells[1].Value.ToString();
				result.Output		= row.Cells[2].Value.ToString();
				result.GRP			= 'P';
				result.ContainerId  = brickId;

				row.Cells[0].Value = Database.Instance.saveResults(result);
			}

			foreach(DataGridViewRow row in negativeGridView.Rows){
				if(row.IsNewRow)
					break;

				Result result = new Result(brickId);
				if(row.Cells[0].Value.ToString()!=null)
					result.Id		= row.Cells[0].Value.ToString();

				result.Input		= row.Cells[1].Value.ToString();
				result.Output		= row.Cells[2].Value.ToString();
				result.GRP			= 'N';
				result.ContainerId  = brickId;

				row.Cells[0].Value = Database.Instance.saveResults(result);
			}
		}

		void BtCloseClick(object sender, EventArgs e)
		{
			this.Close();
		}



		void ResultFormKeyPress(object sender, KeyPressEventArgs e)
		{
			MessageBox.Show(e.KeyChar.ToString());
		}
	}
}
